home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / program / multiclr.lha / MC / mc_Plasma.c < prev    next >
C/C++ Source or Header  |  1995-10-02  |  7KB  |  288 lines

  1. /******************************************************************************
  2. **                                                                           **
  3. ** MultiColor-Demo-Plasma                                                    **
  4. **                                                                           **
  5. **---------------------------------------------------------------------------**
  6. ** V2.0 vom 01.10.95                                                         **
  7. ******************************************************************************/
  8.  
  9. #include "sc:source/mc/multicolor.h"
  10.  
  11. /* Protos */
  12.  
  13. void OpenAll(void);
  14. void CloseAll(void);
  15. void Plasma(double frac);
  16. void Usage(void);
  17. /* defines */
  18.  
  19. extern struct ExecBase         *SysBase;
  20. struct IntuitionBase        *IntuitionBase=0l;
  21. struct GfxBase                 *GfxBase=0l;
  22. struct Screen                *scr=0l;
  23. struct Window                *win=0l;
  24. MCHandle                    *mch=0l;
  25.  
  26. struct TagItem scrtags[]={
  27.     SA_Left,        0,
  28.     SA_Top,            0,
  29.     SA_Width,        0,
  30.     SA_Height,        0,
  31.     SA_Depth,        0,
  32.     SA_Colors,        0l,
  33.     SA_Type,        CUSTOMSCREEN,
  34.     SA_DisplayID,    PAL_MONITOR_ID,
  35.     TAG_DONE
  36. };
  37.  
  38. struct TagItem wintags[]={
  39.     WA_Left,        0,
  40.     WA_Top,            0,
  41.     WA_Width,        0,
  42.     WA_Height,        0,
  43.     WA_IDCMP,        IDCMP_MOUSEBUTTONS|IDCMP_RAWKEY,
  44.     WA_Flags,        WFLG_SMART_REFRESH|WFLG_RMBTRAP|WFLG_BORDERLESS|WFLG_ACTIVATE,
  45.     WA_CustomScreen,0l,
  46.     TAG_DONE
  47. };
  48.  
  49. /* Funktions */
  50.  
  51. void OpenAll(void)
  52. {
  53. //    if(!(IntuitionBase=OpenLibrary("intuition.library",37))) CloseAll();
  54.     if(!(IntuitionBase=OpenLibrary("intuition.library",39))) CloseAll();
  55.     if(!(GfxBase=OpenLibrary("graphics.library",37))) CloseAll();
  56.  
  57.     if(!(scr=OpenScreenTagList(0l,scrtags))) CloseAll();
  58.     wintags[6].ti_Data=scr;
  59.  
  60.     if(!(win=OpenWindowTagList(0l,wintags))) CloseAll();
  61. }
  62.  
  63. void CloseAll(void)
  64. {
  65.     if(win)                CloseWindow(win);
  66.     if(scr)                CloseScreen(scr);
  67.     if(GfxBase)            CloseLibrary(GfxBase);
  68.     if(IntuitionBase)    CloseLibrary(IntuitionBase);
  69.     exit(0);
  70. }
  71.  
  72. void Plasma(double frac)
  73. {
  74.     struct IntuiMessage *imsg;
  75.     ULONG iclass;
  76.     USHORT icode;
  77.     register UBYTE quit=0;
  78.     MCPoint akt,c1,c3,c5,c7,c9;
  79.     UWORD f[300][4],dimx,dimy;
  80.     WORD ptr=0;
  81.     double rndf,dimf=frac/(double)(mch->xres*mch->yres);
  82.     UWORD x1,x2,x3,y1,y2,y3;
  83.  
  84.     srand48(time(NULL));            /* init the random-number-generator */
  85.     f[0][0]=0;f[0][1]=0;f[0][2]=mch->xres-1;f[0][3]=mch->yres-1;
  86.  
  87.     akt.r=drand48();akt.g=drand48();akt.b=drand48();
  88.     MC_PutPixel(mch,0,0,akt);
  89.     akt.r=drand48();akt.g=drand48();akt.b=drand48();
  90.     MC_PutPixel(mch,mch->xres-1,0,akt);
  91.     akt.r=drand48();akt.g=drand48();akt.b=drand48();
  92.     MC_PutPixel(mch,mch->xres-1,mch->yres-1,akt);
  93.     akt.r=drand48();akt.g=drand48();akt.b=drand48();
  94.     MC_PutPixel(mch,0,mch->xres-1,akt);
  95.     while(ptr>-1)
  96.     {
  97.         dimx=f[ptr][2]-f[ptr][0];
  98.         dimy=f[ptr][3]-f[ptr][1];
  99.         if(dimx>1 || dimy>1)
  100.         {
  101.             rndf=(dimx*dimy)*dimf;
  102.             x1=f[ptr][0];x3=f[ptr][2];x2=x1+((x3-x1)>>1);
  103.             y1=f[ptr][1];y3=f[ptr][3];y2=y1+((y3-y1)>>1);
  104.             c1=MC_GetPixel(mch,x1,y1);c3=MC_GetPixel(mch,x3,y1);c9=MC_GetPixel(mch,x3,y3);c7=MC_GetPixel(mch,x1,y3);
  105.  
  106.             c5.r=(c1.r+c3.r+c7.r+c9.r)/4.0+(rndf*(0.5-drand48()));
  107.             if(c5.r>1.0) c5.r=1.0;
  108.             if(c5.r<0.0) c5.r=0.0;
  109.             c5.g=(c1.g+c3.g+c7.g+c9.g)/4.0+(rndf*(0.5-drand48()));
  110.             if(c5.g>1.0) c5.g=1.0;
  111.             if(c5.g<0.0) c5.g=0.0;
  112.             c5.b=(c1.b+c3.b+c7.b+c9.b)/4.0+(rndf*(0.5-drand48()));
  113.             if(c5.b>1.0) c5.b=1.0;
  114.             if(c5.b<0.0) c5.b=0.0;
  115.             MC_PutPixel(mch,x2,y2,c5);
  116.             akt=MC_GetPixel(mch,x2,y1);
  117.             if(akt.r==0.0 && akt.g==0.0 && akt.b==0.0)
  118.             {
  119.                 akt.r=(c1.r+c3.r+c5.r)/3.0;
  120.                 akt.g=(c1.g+c3.g+c5.g)/3.0;
  121.                 akt.b=(c1.b+c3.b+c5.b)/3.0;
  122.                 MC_PutPixel(mch,x2,y1,akt); 
  123.             }
  124.             akt=MC_GetPixel(mch,x1,y2);
  125.             if(akt.r==0.0 && akt.g==0.0 && akt.b==0.0)
  126.             {
  127.                 akt.r=(c1.r+c7.r+c5.r)/3.0;
  128.                 akt.g=(c1.g+c7.g+c5.g)/3.0;
  129.                 akt.b=(c1.b+c7.b+c5.b)/3.0;
  130.                 MC_PutPixel(mch,x1,y2,akt); 
  131.             }
  132.             akt=MC_GetPixel(mch,x3,y2);
  133.             if(akt.r==0.0 && akt.g==0.0 && akt.b==0.0)
  134.             {
  135.                 akt.r=(c3.r+c9.r+c5.r)/3.0;
  136.                 akt.g=(c3.g+c9.g+c5.g)/3.0;
  137.                 akt.b=(c3.b+c9.b+c5.b)/3.0;
  138.                 MC_PutPixel(mch,x3,y2,akt); 
  139.             }
  140.             akt=MC_GetPixel(mch,x2,y3);
  141.             if(akt.r==0.0 && akt.g==0.0 && akt.b==0.0)
  142.             {
  143.                 akt.r=(c7.r+c9.r+c5.r)/3.0;
  144.                 akt.g=(c7.g+c9.g+c5.g)/3.0;
  145.                 akt.b=(c7.b+c9.b+c5.b)/3.0;
  146.                 MC_PutPixel(mch,x2,y3,akt); 
  147.             }
  148.             f[ptr][2]=x2;f[ptr][3]=y2;ptr++;
  149.             f[ptr][0]=x2;f[ptr][1]=y1;f[ptr][2]=x3;f[ptr][3]=y2;ptr++;
  150.             f[ptr][0]=x2;f[ptr][1]=y2;f[ptr][2]=x3;f[ptr][3]=y3;ptr++;
  151.             f[ptr][0]=x1;f[ptr][1]=y2;f[ptr][2]=x2;f[ptr][3]=y3;
  152.             if(ptr>250)
  153.             {
  154.                 printf("stack overflow\n");
  155.                 ptr=-1;
  156.             }
  157.         }
  158.         else ptr--;
  159.     }
  160.  
  161.     while(!quit)
  162.     {
  163.         WaitPort(win->UserPort);
  164.         while(imsg=GetMsg(win->UserPort))
  165.         {
  166.             iclass    =imsg->Class;
  167.             icode    =imsg->Code;
  168.             ReplyMsg(imsg);
  169.             switch(iclass)
  170.             {
  171.                 case IDCMP_RAWKEY:
  172.                     switch(icode)
  173.                     {
  174.                         case 0x45:        /* ESC */
  175.                         case 0x40:        /* Space */
  176.                             quit=1;break;
  177.                     }
  178.                     break;
  179.             }
  180.         }
  181.     }
  182. }
  183.  
  184. void Usage(void)
  185. {
  186.     printf("Usage \n");
  187.     printf("\tmc_plasma typ res chaos\n");
  188.     printf("\tres\typ | 0=ECS | 1=AGA,GFX-Card\n");
  189.     printf("\t--------+-------+---------------\n");
  190.     printf("\t e (ehb)| 64    | -             \n");
  191.     printf("\t l (low)| 32    | 256           \n");
  192.     printf("\t h (hi )| 16    | 256           \n");
  193.     printf("\t s (shi)| --    | 256           \n");
  194.     printf("\t--------+-------+---------------\n");
  195.     printf("\n\tchaos smothness\n");
  196. }
  197.  
  198. void main(int argc,char *argv[])
  199. {
  200.     UBYTE dep,typ,fail=0;
  201.     char res;
  202.     double frac=20.0;
  203.  
  204.     if(argc>=3)
  205.     {
  206.         if(argc==4) frac=atof(argv[3]);
  207.         typ=atoi(argv[1])&1;
  208.         res=argv[2][0];
  209.  
  210.         switch(typ)
  211.         {
  212.             case 0:        /* ECS */
  213.                 switch(res)
  214.                 {
  215.                     case 'E':
  216.                     case 'e':
  217.                         scrtags[4].ti_Data=dep=6;
  218.                         wintags[2].ti_Data=scrtags[2].ti_Data=354;        /* 236 */
  219.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  220.                         scrtags[7].ti_Data|=EXTRAHALFBRITELACE_KEY;
  221.                         break;
  222.                     case 'L':
  223.                     case 'l':
  224.                         scrtags[4].ti_Data=dep=5;
  225.                         wintags[2].ti_Data=scrtags[2].ti_Data=354;        /* 236 */
  226.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  227.                         scrtags[7].ti_Data|=LORESLACE_KEY;
  228.                         break;
  229.                     case 'H':
  230.                     case 'h':
  231.                         scrtags[4].ti_Data=dep=4;
  232.                         wintags[2].ti_Data=scrtags[2].ti_Data=708;        /* 472 */
  233.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  234.                         scrtags[7].ti_Data|=HIRESLACE_KEY;
  235.                         break;
  236.                     case 'S':
  237.                     case 's':
  238.                         fail=1;
  239.                         break;
  240.                 }
  241.                 break;
  242.             case 1:        /* AGA,GFX-Card */
  243.                 switch(res)
  244.                 {
  245.                     case 'E':
  246.                     case 'e':
  247.                         fail=1;
  248.                         break;
  249.                     case 'L':
  250.                     case 'l':
  251.                         scrtags[4].ti_Data=dep=8;
  252.                         wintags[2].ti_Data=scrtags[2].ti_Data=354;        /* 236 */
  253.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  254.                         scrtags[7].ti_Data|=LORESLACE_KEY;
  255.                         break;
  256.                     case 'H':
  257.                     case 'h':
  258.                         scrtags[4].ti_Data=dep=8;
  259.                         wintags[2].ti_Data=scrtags[2].ti_Data=708;        /* 472 */
  260.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  261.                         scrtags[7].ti_Data|=HIRESLACE_KEY;
  262.                         break;
  263.                     case 'S':
  264.                     case 's':
  265.                         scrtags[4].ti_Data=dep=8;
  266.                         wintags[2].ti_Data=scrtags[2].ti_Data=1416;        /* 944 */
  267.                         wintags[3].ti_Data=scrtags[3].ti_Data=552;        /* 276 */
  268.                         scrtags[7].ti_Data|=SUPERLACE_KEY;
  269.                         break;
  270.                 }
  271.                 break;
  272.         }
  273.  
  274.         if(!fail)
  275.         {
  276.             OpenAll();
  277.             if(mch=MC_Init(scr,win,dep))
  278.             {
  279.                 Plasma(frac);
  280.                 MC_Free(mch);
  281.             }
  282.         }
  283.         else Usage();
  284.     }
  285.     else Usage();
  286.     CloseAll();
  287. }
  288.